package com.baice.config;

import org.springframework.web.WebApplicationInitializer;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.HandlesTypes;
import java.util.Set;

//实现ServletContainerInitializer接口
//基于java代码的方式初始化DispatcherServlet
@HandlesTypes({MyWebApplicationInitializer.class})
public class MyWebApplicationInitializer extends MyServlet  implements WebApplicationInitializer , ServletContainerInitializer {

    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        ServletRegistration.Dynamic dynamic =servletContext.addServlet("MyDispatcherServlet", getDispatcherServlet());
        dynamic.setLoadOnStartup(1);
        dynamic.addMapping("/");
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        ServletRegistration.Dynamic dynamic =servletContext.addServlet("app", getDispatcherServlet());
        dynamic.setLoadOnStartup(1);
        dynamic.addMapping("/");
    }
}